﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperMap.Data;
using DTGroup.iNek.Model.FingerprintDatabase;
using DTGroup.Networking.Framework.Utils;

namespace DTGroup.iNek.WinUI
{
    public static class ProjectCoordSysType
    {
        /// <summary>
        /// 地图坐标投影
        /// </summary>
        public static PrjCoordSys LatLonPrjCoordSys
        {
            get
            {
                // 设置经纬度投影
                PrjCoordSys prjCoordSys = new PrjCoordSys();
                prjCoordSys.Type = PrjCoordSysType.EarthLongitudeLatitude;
                prjCoordSys.GeoCoordSys.Type = SuperMap.Data.GeoCoordSysType.Wgs1984;
                return prjCoordSys;
            }
        }

        /// <summary>
        /// 摩卡托投影
        /// </summary>
        public static PrjCoordSys MercatorPrjCoordSys
        {
            get
            {
                // 设置经纬度投影
                PrjCoordSys prjCoordSys = new PrjCoordSys();
                prjCoordSys.Type = PrjCoordSysType.UserDefined;
                // 设置地理坐标系
                prjCoordSys.GeoCoordSys.Type = SuperMap.Data.GeoCoordSysType.UserDefined;
                // 投影类型
                prjCoordSys.Projection.Type = SuperMap.Data.ProjectionType.SphereMercator;

                return prjCoordSys;
            }
        }

        private static PrjCoordSys mapPrjCoordSys;
        public static PrjCoordSys MapPrjCoordSys
        {
            get
            {
                return mapPrjCoordSys;
            }
        }

        /// <summary>
        /// 实例化 投影参数
        /// </summary>
        /// <param name="fingerPrintParameter">指纹库参数</param>
        public static void OnInit(FingerPrintDatabaseParameter fingerPrintParameter)
        {
            if (fingerPrintParameter.IsUserWinprop)
            {
                mapPrjCoordSys = new PrjCoordSys(PrjCoordSysType.UserDefined);

                SuperMap.Data.ProjectionType projectionType = StringUtil.TryParse<SuperMap.Data.ProjectionType>(fingerPrintParameter.ProjectionType == "UTM" ? "TransverseMercator" : fingerPrintParameter.ProjectionType);
                // 获取投影
                mapPrjCoordSys.Projection = new Projection(projectionType);

                // 投影参数
                PrjParameter prjParameter = new PrjParameter();
                prjParameter.CentralMeridian = fingerPrintParameter.CentralMeridian;
                prjParameter.CentralParallel = fingerPrintParameter.CentralParallel;
                prjParameter.FalseEasting = fingerPrintParameter.FalseEasting;
                prjParameter.FalseNorthing = fingerPrintParameter.FalseNorthing;
                prjParameter.ScaleFactor = projectionType == SuperMap.Data.ProjectionType.GaussKruger ? 1 : 0.9996;
                mapPrjCoordSys.PrjParameter = prjParameter;

                // 坐标系类型
                GeoCoordSys geoCoordSysObject = new GeoCoordSys(StringUtil.TryParse<SuperMap.Data.GeoCoordSysType>(fingerPrintParameter.GeoCoordSys), GeoSpatialRefType.EarthLongitudeLatitude);
                mapPrjCoordSys.GeoCoordSys = geoCoordSysObject;
            }
            else
            {
                // 设置经纬度投影
                PrjCoordSys prjCoordSys = new PrjCoordSys();
                prjCoordSys.Type = PrjCoordSysType.UserDefined;
                // 设置地理坐标系
                prjCoordSys.GeoCoordSys.Type = SuperMap.Data.GeoCoordSysType.UserDefined;
                // 投影类型
                prjCoordSys.Projection.Type = SuperMap.Data.ProjectionType.SphereMercator;
                mapPrjCoordSys = prjCoordSys;
            }
        }
    }
}
